package com.suep.business.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;
import com.suep.business.domain.Meal;
import java.util.List;

@Mapper
public interface MealMapper {
    @Insert("INSERT INTO meal (category_id, name, price, description, image_url, stock, month_sales, sort_order, is_available, store_id) " +
            "VALUES (#{categoryId}, #{name}, #{price}, #{description}, #{imageUrl}, #{stock}, #{monthSales}, #{sortOrder}, #{isAvailable} ,#{storeId})")
    @Options(useGeneratedKeys = true, keyProperty = "mealId")
    Integer insert(Meal meal);

    @Update("UPDATE meal SET category_id=#{categoryId}, name=#{name}, price=#{price}, description=#{description}, " +
            "image_url=#{imageUrl}, stock=#{stock}, month_sales=#{monthSales}, sort_order=#{sortOrder}, is_available=#{isAvailable} " +
            "WHERE meal_id=#{mealId}")
    Integer update(Meal meal);

    @Delete("DELETE FROM meal WHERE meal_id=#{mealId}")
    Integer deleteById(@Param("mealId") Integer mealId);

    @Select("SELECT * FROM meal WHERE meal_id=#{mealId}")
    Meal selectById(@Param("mealId") Integer mealId);

    @Select("SELECT * FROM meal WHERE store_id=#{storeId} AND category_id=#{categoryId}")
    List<Meal> selectByStoreIdByCategoryId(Integer storeId,Integer categoryId);

    @Select("SELECT * FROM meal WHERE store_id=#{storeId}")
    List<Meal> selectByStoreId(@Param("storeId") Integer storeId);

    @Select("SELECT * FROM meal ORDER BY sort_order LIMIT #{limit} OFFSET #{offset}")
    List<Meal> selectPage(@Param("limit") int limit, @Param("offset") int offset);

    @Select("SELECT COUNT(*) FROM meal")
    Integer countAll();
}
